# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        Young  
# Name:         demo1051
# Description:
# Author:       $赵怡蕾
# Date:         2019/3/27
#-------------------------------------------------------------------------------

class Fibonacci:
    def __init__(self):
        self.a = 0
        self.b = 1

    def __next__(self):
        result = self.a
        self.a,self.b = self.b,self.a + self.b

        if result > 500: raise StopIteration
        return result

    def __iter__(self):
        return self


fibs = Fibonacci()
print(list(fibs))     # 转化成列表 运行结果：[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377]
# print(len(list(fibs)))    # 转化成列表再计算长度 运行结果：15
fibs2 = Fibonacci()
print(fibs2)          # 他是一个对象 运行结果：<__main__.Fibonacci object at 0x00000000027A8908>

for fib in fibs2:
    print(fib,end = " ")     # 运行结果：0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
    # if fib > 500:
    #     break